﻿using ListNode;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MaxDepth
{
//    给定一个二叉树，找出其最大深度。

//二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
    class Program
    {
        static void Main(string[] args)
        {
            TreeNode t1 = new TreeNode(3);
            t1.left = new TreeNode(9);
            t1.right = new TreeNode(20);
            t1.right.left = new TreeNode(15);
            t1.right.right = new TreeNode(7);
            Console.WriteLine(MaxDepth(t1));
            Console.ReadKey();
        }

        public static int MaxDepth(TreeNode root)
        {
            if (root == null) return 0;
            return Math.Max(MaxDepth(root.left), MaxDepth(root.right))+1;
        }

    }
}
